package com.monkey.apple.app.videoApp;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.monkey.apple.R;

import java.util.List;

/**
 * Description:
 * Author: Archur
 * Date: 2017-10-15
 * Time: 15:10
 */


public class VideoAdapter extends ArrayAdapter<VideoItem> {

    private LayoutInflater mInflater;
    private int mResource;

//    public VideoAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull VideoItem[] objects) {
//        super(context, resource, objects);
//        mInflater = LayoutInflater.from(context);
//        mResource = resource;
//    }
//
//    public VideoAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId, @NonNull VideoItem[] objects, LayoutInflater mInflater) {
//        super(context, resource, textViewResourceId, objects);
//        this.mInflater = mInflater;
//    }

    public VideoAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<VideoItem> objects, LayoutInflater mInflater) {
        super(context, resource, objects);
        this.mInflater = mInflater;
        mResource = resource;
    }



    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        if (convertView == null){
            convertView = mInflater.inflate(mResource,parent,false);
        }

        VideoItem item = getItem(position);

        TextView title = (TextView) convertView.findViewById(R.id.video_title);
        title.setText(item.name);

        TextView createTime = (TextView) convertView.findViewById(R.id.video_date);
        createTime.setText(item.createdTime);

        ImageView thumb = (ImageView) convertView.findViewById(R.id.vidoe_thumb);
        thumb.setImageBitmap(item.thumb);

        return convertView;
    }
}
